package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaDeviceParam;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceParamService;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceTypeService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/pcbaDeviceParam")
@CrossOrigin
public class PcbaDeviceParamController {

    @Autowired
    private PcbaDeviceParamService pcbaDeviceParamService;

    @Autowired
    private PcbaDeviceTypeService pcbaDeviceTypeService;

    @PostMapping("/getAllPcbaDeviceParam")
    public Result getAllPcbaDeviceParam(HttpServletRequest request, Integer pcbaDeviceTypeId, Integer pcbaDeviceParamTypeId, String searchPcbaDeviceParamName) {
        try {
            return ResultUtil.success(pcbaDeviceParamService.getAllPcbaDeviceParam(request, pcbaDeviceTypeId, pcbaDeviceParamTypeId, searchPcbaDeviceParamName));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/analysisPcbaDeviceParamExcel")
    public Result analysisPcbaDeviceParamExcel(MultipartFile file) {
        return pcbaDeviceParamService.analysisPcbaDeviceParamExcel(file);
    }

    @PostMapping("/deleteById")
    public Result deleteById(Integer pcbaDeviceParamId) {
        return pcbaDeviceParamService.deleteById(pcbaDeviceParamId);
    }

    @PostMapping("/addOrUpdatePcbaDeviceParam")
    public Result addOrUpdatePcbaDeviceParam(PcbaDeviceParam pcbaDeviceParam, String mode) {
        return pcbaDeviceParamService.addOrUpdatePcbaDeviceParam(pcbaDeviceParam, mode);
    }

    @PostMapping("/exportPcbaDeviceParamExcel")
    public Result exportPcbaDeviceParamExcel() {
        return pcbaDeviceParamService.exportPcbaDeviceParamExcel();
    }

    @PostMapping("/exportPcbaDeviceParamExcelByDeviceType")
    public Result exportPcbaDeviceParamExcelByDeviceType(Integer pcbaDeviceTypeId) {
        return pcbaDeviceParamService.exportPcbaDeviceParamExcelByDeviceType(pcbaDeviceTypeId);
    }

    @PostMapping("/importPcbaDeviceParamExcelByDeviceType")
    public Result importPcbaDeviceParamExcelByDeviceType(Integer pcbaDeviceTypeId, MultipartFile file) {
        return pcbaDeviceParamService.importPcbaDeviceParamExcelByDeviceType(pcbaDeviceTypeId, file);
    }

    @PostMapping("/getPcbaDeviceParamByKey")
    public Result getPcbaDeviceParamByKey(String pcbaDeviceParamKey) {
        return pcbaDeviceParamService.getPcbaDeviceParamByKey(pcbaDeviceParamKey);
    }
}
